package com.wuliang.blog.repositories;

import com.wuliang.blog.core.basic.BaseRepository;
import com.wuliang.blog.entities.Article;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author WuLiang
 */
@Repository
@Transactional(rollbackFor = { Exception.class })
public interface ArticleRepository extends BaseRepository<Article> {

    @Query("select count(ta.ID) as classificationCount, tc.classificationName as classificationName\n" +
           "from Article ta\n" +
           "left join Classification tc on tc.ID = ta.classificationId \n" +
           "group by ta.classificationId")
    Map<String, Object> getCountGroupByClassification();

}
